package com.taoym.voucher.admin.controller;

import com.taoym.voucher.admin.entity.dto.XcxAddTextDTO;
import com.taoym.voucher.admin.entity.vo.XcxGetTextVO;
import com.taoym.voucher.admin.service.XcxTextService;
import com.taoym.voucher.common.response.Response;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * @coder taoym
 * @datetime 2021/8/13 20:37
 * @desc
 */
@RestController
@RequestMapping("/xcx/text")
@Api(tags = "小程序文本控制器")
public class XcxTextController {

    @Autowired
    private XcxTextService xcxTextService;

    @PostMapping("/add")
    @ApiOperation("添加文本")
    public Response<Boolean> addText(@RequestBody @Valid XcxAddTextDTO data) {
        return Response.success(xcxTextService.addText(data));
    }

    @GetMapping("/list")
    @ApiOperation("查询文本内容")
    public Response<List<XcxGetTextVO>> listTexts() {
        return Response.success(xcxTextService.listTexts());
    }

    @GetMapping("/delete")
    @ApiOperation("删除文本内容")
    public Response<Integer> deleteText(@RequestParam @NotNull(message = "文本编号不能为空") Integer id) {
        return Response.success(xcxTextService.deleteText(id));
    }
}
